import request from '@/utils/request'
const baseUrl = '/project'


// 获取教师项目列表
export const getTeacherProjects = (query) => {
  return request({
    url: `${baseUrl}/teacher/list`,
    method: 'get',
    params: query
  })
}


// 获取学生参与的项目列表
export function getStudentProjects(query) {
  return request({
    url: '/project/student/list',
    method: 'get',
    params: query
  })
}




// 创建新项目
export function createProject(data) {
  return request({
    url: '/project/create',
    method: 'post',
    data
  })
}

// 添加节点信息
export const addMilestone = (data) => {
  return request({
    url: `/project-milestone/milestone/add`,
    method: 'post',
    data
  })
}

// 获取项目详情
export function getProjectDetail(id) {
  return request({
    url: `${baseUrl}/detail/${id}`,
    method: 'get'
  })
}

// 更新项目信息
export function updateProject(data) {
  return request({
    url: `${baseUrl}/update/project`,
    method: 'put',
    data
  })
}

// 删除项目
export function deleteProject(id) {
  return request({
    url: `${baseUrl}/delete/${id}`,
    method: 'delete'
  })
}

// 邀请学生参与项目
export function inviteStudent(data) {
  return request({
    url: `/project/invite`,
    method: 'post',
    data
  })
}

// 移除项目成员
export function removeMember(memberId) {
  return request({
    url: `/project/remove/member/${memberId}`,
    method: 'delete'
  })
}

// 获取项目节点列表
export function getProjectMilestones(projectId) {
  return request({
    url: `/project-milestone/list/${projectId}`,
    method: 'get'
  })
}

// 创建项目节点
export function createMilestone(projectId, data) {
  return request({
    url: `/project/${projectId}/milestone`,
    method: 'post',
    data
  })
}

// 更新项目节点
export function updateMilestone(data) {
  return request({
    url: `/project-milestone/update`,
    method: 'put',
    data
  })
}

// 删除项目节点
export function deleteMilestone(milestoneId) {
  return request({
    url: `/project/milestone/${milestoneId}`,
    method: 'delete'
  })
}

// 上传节点材料
export function uploadMilestoneDocument(milestoneId, data) {
  return request({
    url: `/project/milestone/${milestoneId}/document`,
    method: 'post',
    data
  })
}

// 获取可邀请的学生列表
export function getInvitableStudents(query) {
  return request({
    url: '/user/students',
    method: 'get',
    params: query
  })
}

// 获取成员列表信息
export const getMemberListData = (projectId) => {
  return request({
    url: `${baseUrl}/member/${projectId}`,
    method: 'get'
  })
}


// 获取项目节点列表和文档
export const getProjectMilestonesAndDocuments = (projectId) => {
  return request({
    url: `${baseUrl}/milestonDetail/${projectId}`,
    method: 'get'
  })
}

// 获取学生的项目邀请列表
export function getStudentInvitations(query) {
  return request({
    url: '/project/student/invitations',
    method: 'get',
    params: query
  })
}

// 接受项目邀请
export function acceptInvitation(invitationId) {
  return request({
    url: `/project/accept/invite/${invitationId}`,
    method: 'put'
  })
}

// 拒绝项目邀请
export function rejectInvitation(invitationId, data) {
  return request({
    url: `/project/refuse/invite/${invitationId}`,
    method: 'put',
    data
  })
}

// 学生上传节点附件
export function uploadStudentMilestoneDocument(milestoneId, formData) {
  return request({
    url: `/project/milestone/${milestoneId}/student/upload`,
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 获取学生节点附件列表
export function getStudentMilestoneDocuments(milestoneId) {
  return request({
    url: `/project/milestone/${milestoneId}/student/documents`,
    method: 'get'
  })
}

// 删除学生节点附件
export function deleteStudentMilestoneDocument(documentId) {
  return request({
    url: `/project/milestone/document/${documentId}`,
    method: 'delete'
  })
}


// 获取学生自己的节点信息
export const getStudentDoucemntInfo = (id)=> {
  return request({
  url: `/project/student/milestone/${id}`,
  method: 'get'
})}

// 保存学生节点附件
export const saveStudentMilestoneInfo = (data) => { 
  return request({
    url: `/project/student/upload/milestone`,
    method: 'post',
    data
  })
}



// 学生项目列表
export const getStudentProjectList = (query) => {
  return request({
    url: '/project/student/project/list',
    method: 'get',
    params: query
  })
}